home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9611 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.2 KB

  1. Path: misery.millcomm.com!usenet
  2. From: danhicks@millcomm.com (Dan Hicks)
  3. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
  4. Subject: Re: GOTO controversy
  5. Date: 12 Mar 1996 05:00:58 GMT
  6. Organization: Millennium Communications, Inc.
  7. Message-ID: <4i30ea$4pu@misery.millcomm.com>
  8. References: <rcshlds.1.000A6705@mailserv.mta.ca> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com> <4hpits$1p1v@b.stat.purdue.edu> <4i0fj8$sd3@tierra.santafe.edu>
  9. Reply-To: danhicks@millcomm.com
  10. NNTP-Posting-Host: dial-39.roch.millcomm.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4i0fj8$sd3@tierra.santafe.edu>, richrcar@internet.roadrunner.com (James Giles) writes:
  14. >In 1968, Edsger Dijkstra wrote a letter to the _Communications_
  15. >_of_the_ACM_ titled "Go To Statement Considered Harmful".  This
  16. >paper has since been widely reprinted.  In 1974, Donald Knuth
  17. >wrote a paper for _Computing_Surveys_ titled "Structured
  18. >Programming with GOTO Statements".  This paper has also been
  19. >widely reprinted.  These were not the first nor the only papers
  20. >written on this subject, but to my mind, they should have been
  21. >the last needed.  Anyone who argues this issue should first
  22. >be required to prove he (or she) has read both these papers.
  23. >Anyone who hasn't read these papers should be ignored out
  24. >of hand.
  25.  
  26. Yep, I read those years ago (along with several titled "'Go To Statement
  27. Considered Harmful' Considered Harmful", etc).  And I've got a copy of
  28. the Dijkstra/Dahl/Hoare book around here somewhere.  What you said (in 
  29. the portion of your post that I've omitted) is certainly true for the 
  30. most part.  Whether or not you use GOTOs, and what sort of structuring 
  31. statements you use otherwise or besides is not really that important.
  32.  
  33. But you failed to spell out what IS important.  The critical factor to 
  34. consider here is how the structure of the program contributes to the 
  35. control of complexity.  First off, it must be understood that "toy" 
  36. examples are meaningless, since complexity isn't a factor at "toy" 
  37. scales.  Thus, the issues involved in the "GOTO controversy" can only be
  38. fully appreciated by those who have been involved in "real" large 
  39. development complex projects -- projects where control of complexity was
  40. a major consideration.
  41.  
  42. Once one is faced with this situation -- a project where complexity 
  43. threatens to make the situation unmanageable -- the desireable features 
  44. of a program structuring model become more apparent.  Foremost, one 
  45. would like to have a model that supports a sort of "nested black box" 
  46. approach.  Given a particular structuring construct (such as a DO-WHILE 
  47. block), one would like to be able to define the function of the 
  48. construct in a manner that's independent of its implementation. 
  49. Dijkstra and Hoare pushed this concept with preconditions and invariants
  50. and the like.  The "invariants" are the key here -- the idea that the
  51. actions of a construct can be described as preserving most of the state
  52. of the system unchanged (even if the state changes temporarily within 
  53. the construct), while other parts of the state change in a well-defined 
  54. fashion (those changes being the "function" of the construct).
  55.  
  56. It's this clear separation of preserved state vs changed state that's 
  57. key:  With ordinary "non-structured" code it's easy for the two to get 
  58. intermingled -- for temporarily changed state to get entwined with the 
  59. changes that are to be a permanent result of the code segment under 
  60. consideration.
  61.  
  62. Proper use of structure prevents this entwinement.  A "structured" code 
  63. segment properly includes the statements at the front that make 
  64. temporary changes to the system state along with statements at the end 
  65. that undo those temporary changes.  And "proper" structure assures that 
  66. there is no way to enter the segment -- making the temporary changes -- 
  67. without subsequently leaving the segment through the code that undoes 
  68. those temporary changes.
  69.  
  70. Proper structure also assures that the stated "function" of the segment 
  71. ALWAYS occurs.  (For this reason, the function statement may include an 
  72. error condition that is included as one of the possible outcomes.)
  73.  
  74. When these conditions are met, then it becomes possible to describe the 
  75. function of the code segment as a true "black box", and this in turn 
  76. allows one to ignore the internals of the segment when considering how 
  77. to "plug" segments together.  Since the same concepts can be applied to 
  78. larger and larger segments (composed of smaller segments), it becomes 
  79. possible to build applications of arbitrary complexity without losing 
  80. control.
  81.  
  82. Exactly what techniques are used to maintain the "invariants" depends on
  83. personal preference, the skills of the programmers, etc.  If programmers
  84. are sufficently skilled and also sufficiently self-controlled, plain old
  85. assembly language will work pretty well (though it suffers the obvious 
  86. productivity problems).  If programmers are not highly skilled, or if 
  87. they can't be counted on to always exercise a high degree of 
  88. self-restraint, then a GOTO-less "structured" language will help 
  89. considerably (though not in itself assure a good outcome).
  90.  
  91. For my own part, I'd like to see more languages incorporate a 
  92. prolog/function/epilog block as the primary structuring construct.  TRY 
  93. blocks come close, but much more could be done.
  94.  
  95. Dan Hicks
  96. http://www.millcomm.com/~danhicks/
  97.  
  98.